package com.uottawa.library.service;

import java.util.List;

import com.uottawa.library.dao.ItemDAO;
import com.uottawa.library.dao.LoanDAO;
import com.uottawa.library.domain.Item;

public class ItemService {
	
	private ItemDAO dao = new ItemDAO();
	private LoanDAO loanDao = new LoanDAO();
	
	public String addItem(int isbn) {
		Item item = new Item();
		item.setIsbn(isbn);
		boolean added = dao.addItem(item);
		String result = (added) ? "success" : "failed! duplicate item";
		return result;
	}

	public String removeItem(int id) {
		String result = null;
		if (dao.isBorrowed(id) == false){
		boolean removed = dao.RemoveItem(id); 
		result = (removed) ? "success" : "failed";
		}
		else{
			result = "failed";
		}
		return result;
	}

	public List<Item> getAllItems() {
		return dao.getAllItems();
	}

	public String updateItem(int id, int isbn) {
		boolean updated = dao.updateItem(id, isbn);
		String result = (updated) ? "success" : "failed";
		return result;
	}

	public List<Item> getAllItems(int isbnInt) {
		return dao.getAllItems(isbnInt);
	}

	public List<Item> getAllAvailableItems(int isbnInt) {
		return dao.getAllAvailableItems(isbnInt);
	}
}
